{% load static %}
<div class="category-container">
    <ul class="main-category-list">
        {% for category in categories %} {#遍历全部主分类#}
        <li class="main-category-item">
            <a href="{% url 'category' category.id %}" class="main-category-link">
                <i class="bi bi-grid"></i> {{ category.name }}
            </a>
            <div class="subcategory-container">
                {% for subcategory in category.subcategories.all %}
                {#遍历全部二级分类  SubCategory 模型通过 category 字段与 Category 模型建立了外键关系  所以category.subcategories.all可以获取二级分类#}
                <div class="subcategory-section">
                    <h4 class="subcategory-heading">
                        <a href="{% url 'subcategory' subcategory.id %}">{{ subcategory.name }}</a>
                    </h4>
                    <div class="product-type-container">
                        {% for product_type in subcategory.product_types.all %}
                        {#遍历全部三级分类 实现方法和二级分类一致#}
                        <a href="{% url 'product_type' product_type.id %}" class="product-type-link">{{ product_type.name }}</a>
                        {% if not forloop.last %} | {% endif %}
                        {% endfor %}
                    </div>
                </div>
                {% endfor %}
            </div>
        </li>
        {% endfor %}
    </ul>
</div> 